package bpm.dao.impl.deptagenda;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import bpm.dao.deptagenda.AgendaUserDao;
import bpm.domain.deptagenda.AgendaUser;

/**
 * 
 * @author wanglong635@126.com
 *
 */
@Repository("agendaUserDao")
public class AgendaUserImpl implements AgendaUserDao{
	@Resource private JdbcTemplate jdbcTemplate;
	
	public void batch(String sql, List<AgendaUser> users) {
		jdbcTemplate.batchUpdate(sql,new AgendaUserBatchSetter(users));
	}

	@SuppressWarnings("unchecked")
	public List<AgendaUser> findList(String sql, Object... objs) {
		return jdbcTemplate.query(sql,objs,new AgendaUserMapper(false));
	}

	public void update(String sql, Object... objs) {
		jdbcTemplate.update(sql,objs);
	}

	
	public void batchRelation(String sql, List<AgendaUser> users) {
		jdbcTemplate.batchUpdate(sql, new AgendaDeptUserBatchSetter(users));
	}

	public AgendaUser find(String sql, RowMapper mapper, Object... objs) {
		try {
			return (AgendaUser) jdbcTemplate.queryForObject(sql, objs,mapper);
		} catch (IncorrectResultSizeDataAccessException e) {
			return null;
		}
	}

}
